//
//  OMHomeBarView.m
//  Weibbo
//
//  Created by lilg on 13-6-17.
//  Copyright (c) 2013年 Omnivores. All rights reserved.
//

#import "OMHomeBarView.h"

@interface OMHomeBarView ()

@property (nonatomic, retain)UIButton  *backButton;
@property (nonatomic, retain)UIButton  *addWordButton;
@property (nonatomic, retain)UIButton  *addImageButton;
@end

@implementation OMHomeBarView
@synthesize backButton;
@synthesize addImageButton;
@synthesize addWordButton;

-(void)dealloc
{
    UIRelease(backButton);
    UIRelease(addWordButton);
    UIRelease(addImageButton);
    [super dealloc];
}

- (id)initWithFrame:(CGRect)frame  Delegate:(id<OMHomeBarViewDelegate>)delegate
{
    self = [super initWithFrame:frame];
    if (self)
    {
        Delegate = delegate;
        self.userInteractionEnabled = YES;
        UIImageView *backImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.frame), 51)];
        [backImageView setImage:[UIImage imageNamed:@"bottom_backGround"]];
        [self addSubview:backImageView];
        [backImageView release];
        
        backButton = [[UIButton alloc]initWithFrame:CGRectMake(61, 0, 27, 51)];
        [backButton setBackgroundImage:[UIImage imageNamed:@"back_normal"] forState:UIControlStateNormal];
        [backButton setBackgroundImage:[UIImage imageNamed:@"back_select"] forState:UIControlStateHighlighted];
        backButton.tag = OMHomeBarClickEvent_Back;
        [backButton addTarget:self action:@selector(ButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:backButton];
        
        addWordButton = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetMaxX(backButton.frame)+25, 0, CGRectGetWidth(backButton.frame), CGRectGetHeight(backButton.frame))];
        [addWordButton setBackgroundImage:[UIImage imageNamed:@"+word_normal"] forState:UIControlStateNormal];
        [addWordButton setBackgroundImage:[UIImage imageNamed:@"+word_select"] forState:UIControlStateHighlighted];
        addWordButton.tag = OMHomeBarClickEvent_AddWord;
        [addWordButton addTarget:self action:@selector(ButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:addWordButton];
        
        addImageButton = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetMaxX(addWordButton.frame)+25, 0, CGRectGetWidth(backButton.frame), CGRectGetHeight(backButton.frame))];
        [addImageButton setBackgroundImage:[UIImage imageNamed:@"+image_normal"] forState:UIControlStateNormal];
        [addImageButton setBackgroundImage:[UIImage imageNamed:@"+image_select"] forState:UIControlStateHighlighted];
        addImageButton.tag = OMHomeBarClickEvent_AddImage;
        [addImageButton addTarget:self action:@selector(ButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:addImageButton];
        
        UIButton  *shareButton = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetMaxX(addImageButton.frame)+33, 0, CGRectGetWidth(backButton.frame), CGRectGetHeight(backButton.frame))];
        [shareButton setBackgroundImage:[UIImage imageNamed:@"share_normal"] forState:UIControlStateNormal];
        [shareButton setBackgroundImage:[UIImage imageNamed:@"share_select"] forState:UIControlStateHighlighted];
        shareButton.tag = OMHomeBarClickEvent_Share;
        [shareButton addTarget:self action:@selector(ButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:shareButton];
        [shareButton release];
    }
    return self;
}

-(void)SetUserInteractionEnabled:(BOOL)enabled;
{
    backButton.userInteractionEnabled = enabled;
    addWordButton.userInteractionEnabled = enabled;
   addImageButton.userInteractionEnabled = enabled;
}

-(void)ButtonClick:(id)sender
{
   [Delegate OMHomeBarViewDelegate:sender];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
